package JUnit;

import com.Protocal.User.User;

import DataBase.IDAOImpl.i_User_Impl;
import junit.framework.TestCase;

public class i_User_ImplTest extends TestCase {

	protected void setUp() throws Exception {
		super.setUp();
		i_User_Impl iu = new i_User_Impl();
		User user = new User();
		user.setUserid("091250001");
		user.setName("User Test1");
		user.setSex(0);
		user.setEmail("fewfre");
		iu.addUser(user);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		i_User_Impl iu = new i_User_Impl();
		iu.deleteUserById("091250001");
	}

	public void testAddUser() {
		i_User_Impl iu = new i_User_Impl();
		User user = new User();
		user.setUserid("091250002");
		user.setName("AddUser Test");
		user.setSex(0);
		user.setEmail("fewfre");
		iu.addUser(user);
		
		User rs = iu.getUserById("091250002");
		assertNotNull(rs);
		iu.deleteUserById("091250002");
		//fail("Not yet implemented");
	}

	public void testDeleteUserById() {
		i_User_Impl iu = new i_User_Impl();
		iu.deleteUserById("091250001");
		User rs = iu.getUserById("091250001");
		assertNull(rs);
		//fail("Not yet implemented");
	}

	public void testGetUserById() {
		i_User_Impl iu = new i_User_Impl();
		User user = new User();
		user.setUserid("091250003");
		user.setName("GetByID test");
		user.setSex(0);
		user.setEmail("fewfre");
		iu.addUser(user);
		
		User rs = iu.getUserById("091250003");
		assertNotNull(rs);
		iu.deleteUserById("091250003");
		//fail("Not yet implemented");
	}

	public void testGetUserByName() {
		i_User_Impl iu = new i_User_Impl();
		User user = new User();
		user.setUserid("091250004");
		user.setName("GetByName Test");
		user.setSex(0);
		user.setEmail("fewfre");
		iu.addUser(user);
		
		User rs = iu.getUserByName("GetByName Test");
		assertTrue(rs.getUserid().equals(user.getUserid()));
		iu.deleteUserById("091250004");
		//fail("Not yet implemented");
	}

	public void testUpdateUser() {
		i_User_Impl iu = new i_User_Impl();
		User user = new User();
		user.setUserid("091250005");
		user.setName("Update Test");
		user.setSex(0);
		user.setEmail("fewfre");
		iu.addUser(user);
		
		user.setName("Update Test New");
		iu.updateUser(user);
		
		User rs = iu.getUserById("091250005");
		assertTrue(rs.getName().equals("Update Test New"));
		iu.deleteUserById("091250005");
		//fail("Not yet implemented");
	}

}
